package com.beep.erp.common.base;

import android.content.Context;

import com.beep.erp.common.rx.RxManage;
import com.trello.rxlifecycle.LifecycleProvider;

/**
 * FileName: BasePresenter
 * description: 用RxJava实现的EventBus
 * Author: jolly
 * Date: 2016/9/12
 */
public abstract class BasePresenter<M, V> {
    protected Context mContext;
    protected M mModel;
    protected V mView;
    protected RxManage mRxManage = new RxManage();

    void setVM(V view, M model) {
        this.mView = view;
        this.mModel = model;
        this.onStart();
    }


    /**
     * 对 ACTIVITY 生命周期进行管理
     * @return
     */
    protected LifecycleProvider getActivityLifecycleProvider() {
        LifecycleProvider provider = null;
        if (null != mContext && mContext instanceof LifecycleProvider) {
            provider =  (LifecycleProvider)mContext;
        }
        return provider;
    }
    public abstract void onStart();

    void onDestroy() {
        mRxManage.clear();
    }
}
